#include "widget.h"
#include "ui_widget.h"

#include <QLabel>
#include <QCalendarWidget>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    getCalendar();
}

Widget::~Widget()
{
    delete ui;
}

void Widget::getCalendar()
{
    QCalendarWidget* calendar = new QCalendarWidget(this);
    QLabel* label = new QLabel(this);

    label->setFixedSize(100,30);
    label->setObjectName("label");

    calendar->move(0,40);
    calendar->setObjectName("calendar");

    connect(calendar, &QCalendarWidget::selectionChanged, this, &Widget::displayDate);
}

void Widget::displayDate()
{
    QCalendarWidget* calendar = findChild<QCalendarWidget*>("calendar");
    QLabel* label = findChild<QLabel*>("label");
    if(calendar && label)
    {
        QDate date = calendar->selectedDate();
        label->setText(date.toString());
    }
}
